set.seed(2020)

Summary

In this report we take the individual experiment files for the E8.5 embryos, and output joint data files, with affine scaled coordinates. Note these objects contain 351 genes for the barcoded genes, not the extra 36 smFISH genes.

library(SingleCellExperiment)
library(scater)
library(scran)
library(ComplexHeatmap)
library(ggplot2)
library(ggrepel)
library(GGally)
library(limma)
library(patchwork)
library(reshape)
library(gtools)
library(scattermore)
library(gganimate)
library(ggmap)
library(randomForest)
library(batchelor)
library(igraph)
library(cowplot)
library(ggpubr)

Load spatial and segmentation functions.

source("spatial_functions.R")
source("segmentation_functions.R")
source("celltype_colours.R")
source("neighbourSegments.R")

Load mRNA data and merge

mRNA_df_12 = readRDS("../Data/TimEmbryos-102219/processed/mRNA_df-102219.Rds")
head(mRNA_df_12)
##   cellID geneID regionID        x        y z seeds intensity  pos   fov  embryo
## 1    135  Abcc4        1  670.522  423.266 2     4       671 Pos0 fov.1 embryo1
## 2     95  Abcc4        2  458.830 1637.477 2     4      1497 Pos0 fov.1 embryo1
## 3    326  Abcc4        3 1503.623  436.123 2     4       459 Pos0 fov.1 embryo1
## 4    280  Abcc4        4 1273.170 1287.838 2     3      1504 Pos0 fov.1 embryo1
## 5    168  Abcc4        5  793.611 1096.647 2     4       338 Pos0 fov.1 embryo1
## 6     25  Abcc4        6   92.681  324.985 2     4      1989 Pos0 fov.1 embryo1
##   Estage                uniqueID x_global y_global
## 1   E8.5 embryo1_Pos0_cell135_z2 1627.150 1335.407
## 2   E8.5  embryo1_Pos0_cell95_z2 1623.945 1353.786
## 3   E8.5 embryo1_Pos0_cell326_z2 1639.760 1335.601
## 4   E8.5 embryo1_Pos0_cell280_z2 1636.272 1348.494
## 5   E8.5 embryo1_Pos0_cell168_z2 1629.013 1345.600
## 6   E8.5  embryo1_Pos0_cell25_z2 1618.403 1333.919
mRNA_df_3 = readRDS("../Data/TimEmbryos-120919/processed/mRNA_df-120919.Rds")
head(mRNA_df_3)
##   cellID geneID regionID        x        y z seeds intensity  pos   fov  embryo
## 1     59  Abcc4        1  280.733  619.147 2     3       526 Pos0 fov.1 embryo3
## 2    193  Abcc4        2  878.495  774.291 2     3       281 Pos0 fov.1 embryo3
## 3     12  Abcc4        3   19.597 1477.334 2     3      1265 Pos0 fov.1 embryo3
## 4    197  Abcc4        4 1005.003 1079.637 2     3       878 Pos0 fov.1 embryo3
## 5     66  Abcc4        5  347.452 1724.847 2     4      1842 Pos0 fov.1 embryo3
## 6    288  Abcc4        6 1480.970 1910.600 2     4        20 Pos0 fov.1 embryo3
##   Estage                uniqueID x_global y_global
## 1   E8.5  embryo3_Pos0_cell59_z2 1801.773 1416.348
## 2   E8.5 embryo3_Pos0_cell193_z2 1820.453 1421.197
## 3   E8.5  embryo3_Pos0_cell12_z2 1793.612 1443.167
## 4   E8.5 embryo3_Pos0_cell197_z2 1824.406 1430.739
## 5   E8.5  embryo3_Pos0_cell66_z2 1803.858 1450.901
## 6   E8.5 embryo3_Pos0_cell288_z2 1839.280 1456.706
mRNA_df = rbind(mRNA_df_12, mRNA_df_3)
rm(mRNA_df_12, mRNA_df_3)

Load cell data and merge

sce_12 = readRDS("../Data/TimEmbryos-102219/processed/sce_all-102219.Rds")
sce_12
## class: SingleCellExperiment 
## dim: 351 34883 
## metadata(0):
## assays(1): counts
## rownames(351): Abcc4 Acp5 ... Zfp57 Zic3
## rowData names(0):
## colnames(34883): embryo1_Pos0_cell1_z2 embryo1_Pos0_cell10_z2 ...
##   embryo2_Pos50_cell99_z2 embryo2_Pos50_cell99_z5
## colData names(20): Area Centroid_1 ... segmentation_vertices_x_global
##   segmentation_vertices_y_global
## reducedDimNames(0):
## spikeNames(0):
## altExpNames(0):
sce_3 = readRDS("../Data/TimEmbryos-120919/processed/sce_all-120919.Rds")
sce_3
## class: SingleCellExperiment 
## dim: 351 25401 
## metadata(0):
## assays(1): counts
## rownames(351): Abcc4 Acp5 ... Zfp57 Zic3
## rowData names(0):
## colnames(25401): embryo3_Pos0_cell1_z2 embryo3_Pos0_cell1_z5 ...
##   embryo3_Pos39_cell99_z2 embryo3_Pos39_cell99_z5
## colData names(20): Area Centroid_1 ... segmentation_vertices_x_global
##   segmentation_vertices_y_global
## reducedDimNames(0):
## spikeNames(0):
## altExpNames(0):
sum(counts(sce_12))
## [1] 8271706
sum(counts(sce_3))
## [1] 4149933
sce = cbind(sce_12,sce_3)
sce
## class: SingleCellExperiment 
## dim: 351 60284 
## metadata(0):
## assays(1): counts
## rownames(351): Abcc4 Acp5 ... Zfp57 Zic3
## rowData names(0):
## colnames(60284): embryo1_Pos0_cell1_z2 embryo1_Pos0_cell10_z2 ...
##   embryo3_Pos39_cell99_z2 embryo3_Pos39_cell99_z5
## colData names(20): Area Centroid_1 ... segmentation_vertices_x_global
##   segmentation_vertices_y_global
## reducedDimNames(0):
## spikeNames(0):
## altExpNames(0):
colData(sce)
## DataFrame with 60284 rows and 20 columns
##                              Area       Centroid_1       Centroid_2
##                         <integer>        <numeric>        <numeric>
## embryo1_Pos0_cell1_z2      732848 1162.89787786826 248.662740431849
## embryo1_Pos0_cell10_z2      10400 56.0692307692308 1391.07846153846
## embryo1_Pos0_cell10_z5       2256 13.4219858156028 1625.81914893617
## embryo1_Pos0_cell100_z2      8144  532.15815324165  1140.8025540275
## embryo1_Pos0_cell100_z5      6592 562.014563106796 2013.20873786408
## ...                           ...              ...              ...
## embryo3_Pos39_cell96_z5     13472 1482.22921615202 412.157957244656
## embryo3_Pos39_cell97_z2      5392 1451.27151335312 222.879821958457
## embryo3_Pos39_cell98_z5     10016 1471.88019169329 1551.13258785943
## embryo3_Pos39_cell99_z2     12448 1502.21722365039 475.194087403599
## embryo3_Pos39_cell99_z5     15440  1487.7725388601 878.769430051814
##                         BoundingBox_1 BoundingBox_2 BoundingBox_3 BoundingBox_4
##                             <numeric>     <numeric>     <integer>     <integer>
## embryo1_Pos0_cell1_z2             0.5           0.5          2048          1168
## embryo1_Pos0_cell10_z2            0.5        1336.5           120           108
## embryo1_Pos0_cell10_z5            0.5        1572.5            32           104
## embryo1_Pos0_cell100_z2         468.5        1080.5           124           116
## embryo1_Pos0_cell100_z5         508.5        1964.5           108            84
## ...                               ...           ...           ...           ...
## embryo3_Pos39_cell96_z5        1404.5         336.5           164           136
## embryo3_Pos39_cell97_z2        1404.5         184.5            92            80
## embryo3_Pos39_cell98_z5        1408.5        1484.5           120           128
## embryo3_Pos39_cell99_z2        1412.5         412.5           168           120
## embryo3_Pos39_cell99_z5        1416.5         808.5           148           152
##                            cellID         z                uniqueID
##                         <integer> <integer>             <character>
## embryo1_Pos0_cell1_z2           1         2   embryo1_Pos0_cell1_z2
## embryo1_Pos0_cell10_z2         10         2  embryo1_Pos0_cell10_z2
## embryo1_Pos0_cell10_z5         10         5  embryo1_Pos0_cell10_z5
## embryo1_Pos0_cell100_z2       100         2 embryo1_Pos0_cell100_z2
## embryo1_Pos0_cell100_z5       100         5 embryo1_Pos0_cell100_z5
## ...                           ...       ...                     ...
## embryo3_Pos39_cell96_z5        96         5 embryo3_Pos39_cell96_z5
## embryo3_Pos39_cell97_z2        97         2 embryo3_Pos39_cell97_z2
## embryo3_Pos39_cell98_z5        98         5 embryo3_Pos39_cell98_z5
## embryo3_Pos39_cell99_z2        99         2 embryo3_Pos39_cell99_z2
## embryo3_Pos39_cell99_z5        99         5 embryo3_Pos39_cell99_z5
##                                 x_global         y_global         pos
##                                <numeric>        <numeric> <character>
## embryo1_Pos0_cell1_z2   1634.60245811226 1332.76393796552        Pos0
## embryo1_Pos0_cell10_z2  1617.84870417668 1350.05636343149        Pos0
## embryo1_Pos0_cell10_z5  1617.20316482436 1353.60956719581        Pos0
## embryo1_Pos0_cell100_z2 1625.05512829614  1346.2680074096        Pos0
## embryo1_Pos0_cell100_z5 1625.50705637515 1359.47337445009        Pos0
## ...                                  ...              ...         ...
## embryo3_Pos39_cell96_z5 1454.31966300475  1487.8799361639       Pos39
## embryo3_Pos39_cell97_z2 1453.35223479228  1481.9649944362       Pos39
## embryo3_Pos39_cell98_z5 1453.99625599042 1523.47289337061       Pos39
## embryo3_Pos39_cell99_z2 1454.94428823907 1489.84981523136       Pos39
## embryo3_Pos39_cell99_z5 1454.49289183938 1502.46154468912       Pos39
##                                 fov      embryo      Estage
##                         <character> <character> <character>
## embryo1_Pos0_cell1_z2         fov.1     embryo1        E8.5
## embryo1_Pos0_cell10_z2        fov.1     embryo1        E8.5
## embryo1_Pos0_cell10_z5        fov.1     embryo1        E8.5
## embryo1_Pos0_cell100_z2       fov.1     embryo1        E8.5
## embryo1_Pos0_cell100_z5       fov.1     embryo1        E8.5
## ...                             ...         ...         ...
## embryo3_Pos39_cell96_z5      fov.40     embryo3        E8.5
## embryo3_Pos39_cell97_z2      fov.40     embryo3        E8.5
## embryo3_Pos39_cell98_z5      fov.40     embryo3        E8.5
## embryo3_Pos39_cell99_z2      fov.40     embryo3        E8.5
## embryo3_Pos39_cell99_z5      fov.40     embryo3        E8.5
##                         segmentation_vertices_x segmentation_vertices_y
##                                   <NumericList>           <NumericList>
## embryo1_Pos0_cell1_z2                                                  
## embryo1_Pos0_cell10_z2                1,2,1,...         335,335,336,...
## embryo1_Pos0_cell10_z5                4,4,3,...         394,395,395,...
## embryo1_Pos0_cell100_z2         132,136,136,...         271,271,272,...
## embryo1_Pos0_cell100_z5         142,143,144,...         492,492,493,...
## ...                                         ...                     ...
## embryo3_Pos39_cell96_z5         368,369,370,...            85,85,86,...
## embryo3_Pos39_cell97_z2         370,373,373,...            47,47,49,...
## embryo3_Pos39_cell98_z5         364,367,371,...         372,372,376,...
## embryo3_Pos39_cell99_z2         372,372,371,...         104,105,105,...
## embryo3_Pos39_cell99_z5         374,375,376,...         203,203,204,...
##                                          segmentation_vertices_x_global
##                                                           <NumericList>
## embryo1_Pos0_cell1_z2                                                  
## embryo1_Pos0_cell10_z2  1617.060546875,1617.12109375,1617.060546875,...
## embryo1_Pos0_cell10_z5     1617.2421875,1617.2421875,1617.181640625,...
## embryo1_Pos0_cell100_z2        1624.9921875,1625.234375,1625.234375,...
## embryo1_Pos0_cell100_z5     1625.59765625,1625.658203125,1625.71875,...
## ...                                                                 ...
## embryo3_Pos39_cell96_z5                       1454,1454.125,1454.25,...
## embryo3_Pos39_cell97_z2                   1454.25,1454.625,1454.625,...
## embryo3_Pos39_cell98_z5                    1453.5,1453.875,1454.375,...
## embryo3_Pos39_cell99_z2                      1454.5,1454.5,1454.375,...
## embryo3_Pos39_cell99_z5                       1454.75,1454.875,1455,...
##                                          segmentation_vertices_y_global
##                                                           <NumericList>
## embryo1_Pos0_cell1_z2                                                  
## embryo1_Pos0_cell10_z2     1349.283203125,1349.283203125,1349.34375,...
## embryo1_Pos0_cell10_z5  1352.85546875,1352.916015625,1352.916015625,...
## embryo1_Pos0_cell100_z2    1345.408203125,1345.408203125,1345.46875,...
## embryo1_Pos0_cell100_z5    1358.7890625,1358.7890625,1358.849609375,...
## ...                                                                 ...
## embryo3_Pos39_cell96_z5                   1485.625,1485.625,1485.75,...
## embryo3_Pos39_cell97_z2                  1480.875,1480.875,1481.125,...
## embryo3_Pos39_cell98_z5                          1521.5,1521.5,1522,...
## embryo3_Pos39_cell99_z2                      1488,1488.125,1488.125,...
## embryo3_Pos39_cell99_z5                    1500.375,1500.375,1500.5,...
rm(sce_12, sce_3)

Affine scaling of embryos in space

Affine scaling here consists of three steps:

  • divide by the width/height of the fov square, here entered manually
  • centre by subtracting the midpoint coordinate
  • flip some embryos for the same top-down and left-right orientation Having done this means that the embryos are on the same physical scale to each other.
# make a dataframe that says what needs to be done for the coordinates for each
# embryo
# 1. scale, 2. center, 3. flip
# still hardcoded so beware!

affine_df = data.frame(
  embryo = c("embryo1", "embryo2","embryo3"),
  scaleFactor_x = c(31,31,64),
  scaleFactor_y = c(31,31,64),
  midpoint_x = tapply(colData(sce)$x_global,colData(sce)$embryo,function(x)mean(range(x))),
  midpoint_y = tapply(colData(sce)$y_global,colData(sce)$embryo,function(x)mean(range(x))),
  flip_x = c(FALSE,TRUE,TRUE),
  flip_y = c(FALSE,FALSE,FALSE), 
  angle = c(0,-20,-35)
)

affine_df
##          embryo scaleFactor_x scaleFactor_y midpoint_x midpoint_y flip_x flip_y
## embryo1 embryo1            31            31   1595.242   1437.530  FALSE  FALSE
## embryo2 embryo2            31            31   1537.228   1663.114   TRUE  FALSE
## embryo3 embryo3            64            64   1637.777   1515.399   TRUE  FALSE
##         angle
## embryo1     0
## embryo2   -20
## embryo3   -35
angles = affine_df$angle
names(angles) <- rownames(affine_df)

x_global_scaled <- colData(sce)$x_global/affine_df[colData(sce)$embryo,"scaleFactor_x"]

y_global_scaled <- colData(sce)$y_global/affine_df[colData(sce)$embryo,"scaleFactor_y"]

x_global_scaled_centred = x_global_scaled - affine_df[colData(sce)$embryo,"midpoint_x"]/affine_df[colData(sce)$embryo,"scaleFactor_x"]

y_global_scaled_centred = y_global_scaled - affine_df[colData(sce)$embryo,"midpoint_y"]/affine_df[colData(sce)$embryo,"scaleFactor_y"]

x_global_scaled_centred_flipped = x_global_scaled_centred*ifelse(affine_df[colData(sce)$embryo, "flip_x"], -1, 1)

y_global_scaled_centred_flipped = y_global_scaled_centred*ifelse(affine_df[colData(sce)$embryo, "flip_y"], -1, 1)

df_global_scaled_centred_flipped = data.frame(embryo = sce$embryo,
                                              x = x_global_scaled_centred_flipped,
                                              y = y_global_scaled_centred_flipped)
out = rotateDF(df_global_scaled_centred_flipped, x = "x", y = "y", ang = angles)

colData(sce)$x_global_affine <- out$x
colData(sce)$y_global_affine <- out$y

# scaled and centred and flipped
g = ggplot(as.data.frame(colData(sce))) + 
  geom_point(aes(x = x_global_affine,
                 y = -y_global_affine,
                 colour = embryo), fill = NA, size = 0.5, alpha = 0.15) + 
  coord_fixed() +
  theme_classic() +
  ggtitle("All cells in affine scaling") +
  NULL
g

g + facet_grid(z~embryo)

Also do this with the segmentation numericLists. This takes a long time to run.

x_global_segments <- colData(sce)$segmentation_vertices_x_global

x_global_segments_affine = sapply(names(x_global_segments), function(n) {
  
  # print(n)
  
  x_global_segment <- x_global_segments[[n]]
  if (length(x_global_segment) == 0) return(x_global_segment)
  
  embryo_val = colData(sce)[n,"embryo"]
  
  # 1. scale
  x_global_segment_scaled <- x_global_segment/affine_df[embryo_val,"scaleFactor_x"]
  
  # 2. center - note to scale the center too!
  x_global_segment_scaled_centred <- x_global_segment_scaled - affine_df[embryo_val,"midpoint_x"]/affine_df[embryo_val,"scaleFactor_x"]
  
  # 3. flip if needed
  if (affine_df[embryo_val,"flip_x"]) {
    x_global_segment_scaled_centred_flip = -x_global_segment_scaled_centred
  } else {
    x_global_segment_scaled_centred_flip <- x_global_segment_scaled_centred
  }
  
  return(x_global_segment_scaled_centred_flip)
}, simplify = FALSE)


y_global_segments <- colData(sce)$segmentation_vertices_y_global

y_global_segments_affine = sapply(names(y_global_segments), function(n) {
  
  # print(n)
  
  y_global_segment <- y_global_segments[[n]]
  if (length(y_global_segment) == 0) return(y_global_segment)
  
  embryo_val = colData(sce)[n,"embryo"]
  
  # 1. scale
  y_global_segment_scaled <- y_global_segment/affine_df[embryo_val,"scaleFactor_y"]
  
  # 2. center - note to scale the center too!
  y_global_segment_scaled_centred <- y_global_segment_scaled - affine_df[embryo_val,"midpoint_y"]/affine_df[embryo_val,"scaleFactor_y"]
  
  # 3. flip if needed
  if (affine_df[embryo_val,"flip_y"]) {
    y_global_segment_scaled_centred_flip = -y_global_segment_scaled_centred
  } else {
    y_global_segment_scaled_centred_flip <- y_global_segment_scaled_centred
  }
  
  return(y_global_segment_scaled_centred_flip)
}, simplify = FALSE)

x_global_segments_affine_rotated = x_global_segments_affine
y_global_segments_affine_rotated = y_global_segments_affine

# a list of dataframes
# global_segments = sapply(names(y_global_segments), function(n) {

for (n in names(y_global_segments)) {
  
  # print(n)
  
  if (length(x_global_segments_affine[[n]]) == 0) next
  
  if (FALSE) {
    plot(x_global_segments_affine[[n]],
         y_global_segments_affine[[n]], type = "l", xlim = c(-3,3), ylim= c(-3,3))
  }
  
  df_global_scaled_centred_flipped = data.frame(embryo = as.character(colData(sce)[n,"embryo"]),
                                                x = x_global_segments_affine[[n]],
                                                y = y_global_segments_affine[[n]])
  out = rotateDF(df_global_scaled_centred_flipped, xname = "x", yname = "y", ang = angles)
  
  if (FALSE) {
    points(out$x,
         out$y, type = "l", col = "blue")
  }
  
  x_global_segments_affine_rotated[[n]] <- out$x
  y_global_segments_affine_rotated[[n]] <- out$y
  
}

colData(sce)$segmentation_vertices_x_global_affine <- IRanges::NumericList(x_global_segments_affine_rotated)
colData(sce)$segmentation_vertices_y_global_affine <- IRanges::NumericList(y_global_segments_affine_rotated)

Also do this for the mRNA dataframes

# 1. scale, 2. center, 3. flip if needed
mRNA_x_global_affine <- mRNA_df$x_global
for (embryo_val in as.character(unique(affine_df$embryo))) {
  mRNA_x_global_affine[mRNA_df$embryo == embryo_val] <-
    ((mRNA_df$x_global[mRNA_df$embryo == embryo_val]/affine_df[embryo_val,"scaleFactor_x"]) - affine_df[embryo_val,"midpoint_x"]/affine_df[embryo_val,"scaleFactor_x"])*(ifelse(affine_df[embryo_val,"flip_x"], -1, 1))
}

mRNA_y_global_affine <- mRNA_df$y_global
for (embryo_val in as.character(unique(affine_df$embryo))) {
  mRNA_y_global_affine[mRNA_df$embryo == embryo_val] <-
    ((mRNA_df$y_global[mRNA_df$embryo == embryo_val]/affine_df[embryo_val,"scaleFactor_y"]) - affine_df[embryo_val,"midpoint_y"]/affine_df[embryo_val,"scaleFactor_y"])*(ifelse(affine_df[embryo_val,"flip_y"], -1, 1))
}

df_global_scaled_centred_flipped = data.frame(embryo = mRNA_df$embryo,
                                              x = mRNA_x_global_affine,
                                              y = mRNA_y_global_affine)
out = rotateDF(df_global_scaled_centred_flipped, x = "x", y = "y", ang = angles)

mRNA_df$x_global_affine <- out$x
mRNA_df$y_global_affine <- out$y

# mRNA_df$x_global_affine <- mRNA_x_global_affine
# mRNA_df$y_global_affine <- mRNA_y_global_affine

Graph using boundaries

boundary_polygons = getSegmentationVerticesDF(
  colData(sce),
  xname = "segmentation_vertices_x_global_affine",
  yname = "segmentation_vertices_y_global_affine",
  othercols = c("uniqueID","z","embryo","pos"))

boundary_bbox = do.call(
  rbind,
  lapply(
    split.data.frame(boundary_polygons, 
                     list(boundary_polygons$pos,
                          boundary_polygons$embryo,
                          boundary_polygons$z)),
    function(df) cbind(as.data.frame(t(make_bbox(segmentation_vertices_x_global_affine,
                                                 segmentation_vertices_y_global_affine,
                                                 data = df, f = 0))),
                       embryo = df$embryo[1],
                       pos = df$pos[1],
                       z = df$z[1]))
)
boundary_bbox <- na.omit(boundary_bbox)
for (zval in unique(boundary_polygons$z)) {
  
  g = ggplot(subset(as.data.frame(colData(sce)), z %in% zval)) + 
    geom_point(aes(group = uniqueID,
                     x = x_global_affine,
                     y = -y_global_affine), fill = NA, colour = "black") + 
    facet_wrap(embryo~., nrow = 3) +
    coord_fixed() +
    theme_classic() +
    ggtitle(zval) +
    NULL
  print(g)
}

for (zval in unique(boundary_polygons$z)) {
  
  g = ggplot(subset(boundary_polygons, z %in% zval)) + 
    geom_polygon(aes(group = uniqueID,
                     x = segmentation_vertices_x_global_affine,
                     y = -segmentation_vertices_y_global_affine), fill = NA, colour = "black") + 
    facet_wrap(embryo~., nrow = 3) +
    coord_fixed() +
    theme_classic() +
    theme(legend.position = "none") +
    ggtitle(zval) +
    NULL
  print(g)
  
  gg = g + geom_rect(data = subset(boundary_bbox, z %in% zval),
                     aes(xmin = left, 
                         xmax = right,
                         ymin = -top,
                         ymax = -bottom),
                     color="red", fill= "transparent", linetype = "dotted") +
    ggtitle("Horizontal Bounding box added") +
    NULL    
  print(gg)
}

Basic Exploration

Calculate QC metrics and extract the column data as a separate object

sce <- scater::addPerCellQC(sce)
cData = as.data.frame(colData(sce))
cData$embryo_pos = factor(paste0(cData$embryo,"_", cData$pos),
                          levels = mixedsort(unique(as.character(paste0(cData$embryo,"_", cData$pos)))))
sce$embryo_pos <- cData$embryo_pos
mRNA_df$embryo_pos = factor(paste0(mRNA_df$embryo,"_", mRNA_df$pos),
                            levels = mixedsort(unique(as.character(paste0(mRNA_df$embryo,"_", mRNA_df$pos)))))


cData$embryo_pos_z = factor(paste0(cData$embryo,"_", cData$pos, "_", cData$z),
                          levels = mixedsort(unique(as.character(paste0(cData$embryo,"_", cData$pos, "_", cData$z)))))
sce$embryo_pos_z <- cData$embryo_pos_z
mRNA_df$embryo_pos_z = factor(paste0(mRNA_df$embryo,"_", mRNA_df$pos, "_", mRNA_df$z),
                            levels = mixedsort(unique(as.character(paste0(mRNA_df$embryo,"_", mRNA_df$pos, "_", mRNA_df$z)))))

Save output

sce
## class: SingleCellExperiment 
## dim: 351 60284 
## metadata(0):
## assays(1): counts
## rownames(351): Abcc4 Acp5 ... Zfp57 Zic3
## rowData names(0):
## colnames(60284): embryo1_Pos0_cell1_z2 embryo1_Pos0_cell10_z2 ...
##   embryo3_Pos39_cell99_z2 embryo3_Pos39_cell99_z5
## colData names(33): Area Centroid_1 ... embryo_pos embryo_pos_z
## reducedDimNames(0):
## spikeNames(0):
## altExpNames(0):
head(colData(sce))
## DataFrame with 6 rows and 33 columns
##                              Area       Centroid_1       Centroid_2
##                         <integer>        <numeric>        <numeric>
## embryo1_Pos0_cell1_z2      732848 1162.89787786826 248.662740431849
## embryo1_Pos0_cell10_z2      10400 56.0692307692308 1391.07846153846
## embryo1_Pos0_cell10_z5       2256 13.4219858156028 1625.81914893617
## embryo1_Pos0_cell100_z2      8144  532.15815324165  1140.8025540275
## embryo1_Pos0_cell100_z5      6592 562.014563106796 2013.20873786408
## embryo1_Pos0_cell101_z2      8560 528.376635514019 1024.55607476636
##                         BoundingBox_1 BoundingBox_2 BoundingBox_3 BoundingBox_4
##                             <numeric>     <numeric>     <integer>     <integer>
## embryo1_Pos0_cell1_z2             0.5           0.5          2048          1168
## embryo1_Pos0_cell10_z2            0.5        1336.5           120           108
## embryo1_Pos0_cell10_z5            0.5        1572.5            32           104
## embryo1_Pos0_cell100_z2         468.5        1080.5           124           116
## embryo1_Pos0_cell100_z5         508.5        1964.5           108            84
## embryo1_Pos0_cell101_z2         480.5         968.5           112           112
##                            cellID         z                uniqueID
##                         <integer> <integer>             <character>
## embryo1_Pos0_cell1_z2           1         2   embryo1_Pos0_cell1_z2
## embryo1_Pos0_cell10_z2         10         2  embryo1_Pos0_cell10_z2
## embryo1_Pos0_cell10_z5         10         5  embryo1_Pos0_cell10_z5
## embryo1_Pos0_cell100_z2       100         2 embryo1_Pos0_cell100_z2
## embryo1_Pos0_cell100_z5       100         5 embryo1_Pos0_cell100_z5
## embryo1_Pos0_cell101_z2       101         2 embryo1_Pos0_cell101_z2
##                                 x_global         y_global         pos
##                                <numeric>        <numeric> <character>
## embryo1_Pos0_cell1_z2   1634.60245811226 1332.76393796552        Pos0
## embryo1_Pos0_cell10_z2  1617.84870417668 1350.05636343149        Pos0
## embryo1_Pos0_cell10_z5  1617.20316482436 1353.60956719581        Pos0
## embryo1_Pos0_cell100_z2 1625.05512829614  1346.2680074096        Pos0
## embryo1_Pos0_cell100_z5 1625.50705637515 1359.47337445009        Pos0
## embryo1_Pos0_cell101_z2 1624.99788852585 1344.50841714734        Pos0
##                                 fov      embryo      Estage
##                         <character> <character> <character>
## embryo1_Pos0_cell1_z2         fov.1     embryo1        E8.5
## embryo1_Pos0_cell10_z2        fov.1     embryo1        E8.5
## embryo1_Pos0_cell10_z5        fov.1     embryo1        E8.5
## embryo1_Pos0_cell100_z2       fov.1     embryo1        E8.5
## embryo1_Pos0_cell100_z5       fov.1     embryo1        E8.5
## embryo1_Pos0_cell101_z2       fov.1     embryo1        E8.5
##                         segmentation_vertices_x segmentation_vertices_y
##                                   <NumericList>           <NumericList>
## embryo1_Pos0_cell1_z2                                                  
## embryo1_Pos0_cell10_z2                1,2,1,...         335,335,336,...
## embryo1_Pos0_cell10_z5                4,4,3,...         394,395,395,...
## embryo1_Pos0_cell100_z2         132,136,136,...         271,271,272,...
## embryo1_Pos0_cell100_z5         142,143,144,...         492,492,493,...
## embryo1_Pos0_cell101_z2         124,124,127,...         243,244,244,...
##                                          segmentation_vertices_x_global
##                                                           <NumericList>
## embryo1_Pos0_cell1_z2                                                  
## embryo1_Pos0_cell10_z2  1617.060546875,1617.12109375,1617.060546875,...
## embryo1_Pos0_cell10_z5     1617.2421875,1617.2421875,1617.181640625,...
## embryo1_Pos0_cell100_z2        1624.9921875,1625.234375,1625.234375,...
## embryo1_Pos0_cell100_z5     1625.59765625,1625.658203125,1625.71875,...
## embryo1_Pos0_cell101_z2    1624.5078125,1624.5078125,1624.689453125,...
##                                          segmentation_vertices_y_global
##                                                           <NumericList>
## embryo1_Pos0_cell1_z2                                                  
## embryo1_Pos0_cell10_z2     1349.283203125,1349.283203125,1349.34375,...
## embryo1_Pos0_cell10_z5  1352.85546875,1352.916015625,1352.916015625,...
## embryo1_Pos0_cell100_z2    1345.408203125,1345.408203125,1345.46875,...
## embryo1_Pos0_cell100_z5    1358.7890625,1358.7890625,1358.849609375,...
## embryo1_Pos0_cell101_z2    1343.712890625,1343.7734375,1343.7734375,...
##                           x_global_affine   y_global_affine
##                                 <numeric>         <numeric>
## embryo1_Pos0_cell1_z2     1.2697044048663 -3.37956595864406
## embryo1_Pos0_cell10_z2  0.729260729524981 -2.82174578232248
## embryo1_Pos0_cell10_z5  0.708436879449962 -2.70712630605406
## embryo1_Pos0_cell100_z2 0.961726023700962 -2.94395081528682
## embryo1_Pos0_cell100_z5 0.976304348830425 -2.51797123333536
## embryo1_Pos0_cell101_z2 0.959879579498015 -3.00071179148854
##                                             segmentation_vertices_x_global_affine
##                                                                     <NumericList>
## embryo1_Pos0_cell1_z2                                                            
## embryo1_Pos0_cell10_z2  0.703836300438439,0.705789425438439,0.703836300438439,...
## embryo1_Pos0_cell10_z5  0.709695675438439,0.709695675438439,0.707742550438439,...
## embryo1_Pos0_cell100_z2 0.959695675438439,0.967508175438439,0.967508175438439,...
## embryo1_Pos0_cell100_z5 0.979226925438439,0.981180050438439,0.983133175438439,...
## embryo1_Pos0_cell101_z2 0.944070675438439,0.944070675438439,0.949930050438439,...
##                                             segmentation_vertices_y_global_affine
##                                                                     <NumericList>
## embryo1_Pos0_cell1_z2                                                            
## embryo1_Pos0_cell10_z2  -2.84668643737056,-2.84668643737056,-2.84473331237056,...
## embryo1_Pos0_cell10_z5  -2.73145206237056,-2.72949893737056,-2.72949893737056,...
## embryo1_Pos0_cell100_z2 -2.97168643737056,-2.97168643737056,-2.96973331237056,...
## embryo1_Pos0_cell100_z5 -2.54004581237056,-2.54004581237056,-2.53809268737056,...
## embryo1_Pos0_cell101_z2 -3.02637393737056,-3.02442081237056,-3.02442081237056,...
##                               sum  detected   percent_top_50  percent_top_100
##                         <numeric> <integer>        <numeric>        <numeric>
## embryo1_Pos0_cell1_z2        5444       341 57.5128581925055 75.6061719324026
## embryo1_Pos0_cell10_z2        455       160 66.5934065934066 86.8131868131868
## embryo1_Pos0_cell10_z5         83        56 92.7710843373494              100
## embryo1_Pos0_cell100_z2       107        80 71.9626168224299              100
## embryo1_Pos0_cell100_z5       264       121 70.4545454545455 92.0454545454545
## embryo1_Pos0_cell101_z2       106        70 81.1320754716981              100
##                          percent_top_200 percent_top_500     total   embryo_pos
##                                <numeric>       <numeric> <numeric>     <factor>
## embryo1_Pos0_cell1_z2   91.7340191036003             100      5444 embryo1_Pos0
## embryo1_Pos0_cell10_z2               100             100       455 embryo1_Pos0
## embryo1_Pos0_cell10_z5               100             100        83 embryo1_Pos0
## embryo1_Pos0_cell100_z2              100             100       107 embryo1_Pos0
## embryo1_Pos0_cell100_z5              100             100       264 embryo1_Pos0
## embryo1_Pos0_cell101_z2              100             100       106 embryo1_Pos0
##                           embryo_pos_z
##                               <factor>
## embryo1_Pos0_cell1_z2   embryo1_Pos0_2
## embryo1_Pos0_cell10_z2  embryo1_Pos0_2
## embryo1_Pos0_cell10_z5  embryo1_Pos0_5
## embryo1_Pos0_cell100_z2 embryo1_Pos0_2
## embryo1_Pos0_cell100_z5 embryo1_Pos0_5
## embryo1_Pos0_cell101_z2 embryo1_Pos0_2
dim(mRNA_df)
## [1] 12421639       19
head(mRNA_df)
##   cellID geneID regionID        x        y z seeds intensity  pos   fov  embryo
## 1    135  Abcc4        1  670.522  423.266 2     4       671 Pos0 fov.1 embryo1
## 2     95  Abcc4        2  458.830 1637.477 2     4      1497 Pos0 fov.1 embryo1
## 3    326  Abcc4        3 1503.623  436.123 2     4       459 Pos0 fov.1 embryo1
## 4    280  Abcc4        4 1273.170 1287.838 2     3      1504 Pos0 fov.1 embryo1
## 5    168  Abcc4        5  793.611 1096.647 2     4       338 Pos0 fov.1 embryo1
## 6     25  Abcc4        6   92.681  324.985 2     4      1989 Pos0 fov.1 embryo1
##   Estage                uniqueID x_global y_global x_global_affine
## 1   E8.5 embryo1_Pos0_cell135_z2 1627.150 1335.407       1.0292865
## 2   E8.5  embryo1_Pos0_cell95_z2 1623.945 1353.786       0.9259213
## 3   E8.5 embryo1_Pos0_cell326_z2 1639.760 1335.601       1.4360741
## 4   E8.5 embryo1_Pos0_cell280_z2 1636.272 1348.494       1.3235482
## 5   E8.5 embryo1_Pos0_cell168_z2 1629.013 1345.600       1.0893885
## 6   E8.5  embryo1_Pos0_cell25_z2 1618.403 1333.919       0.7471376
##   y_global_affine   embryo_pos   embryo_pos_z
## 1       -3.294310 embryo1_Pos0 embryo1_Pos0_2
## 2       -2.701434 embryo1_Pos0 embryo1_Pos0_2
## 3       -3.288033 embryo1_Pos0 embryo1_Pos0_2
## 4       -2.872156 embryo1_Pos0 embryo1_Pos0_2
## 5       -2.965511 embryo1_Pos0 embryo1_Pos0_2
## 6       -3.342299 embryo1_Pos0 embryo1_Pos0_2
saveRDS(sce, file = "../analysis_output/E8.5/E8.5_sce_unfiltered.Rds")
saveRDS(mRNA_df, file = "../analysis_output/E8.5/E8.5_mRNA_df_unfiltered.Rds")
sessionInfo()
## R version 3.6.1 (2019-07-05)
## Platform: x86_64-apple-darwin18.6.0 (64-bit)
## Running under: macOS Mojave 10.14.6
## 
## Matrix products: default
## BLAS/LAPACK: /usr/local/Cellar/openblas/0.3.9/lib/libopenblasp-r0.3.9.dylib
## 
## locale:
## [1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8
## 
## attached base packages:
##  [1] grid      parallel  stats4    stats     graphics  grDevices utils    
##  [8] datasets  methods   base     
## 
## other attached packages:
##  [1] ggpubr_0.2.5                magrittr_1.5               
##  [3] cowplot_1.0.0               igraph_1.2.4.2             
##  [5] batchelor_1.2.4             randomForest_4.6-14        
##  [7] ggmap_3.0.0                 gganimate_1.0.5            
##  [9] scattermore_0.4             gtools_3.8.1               
## [11] reshape_0.8.8               patchwork_1.0.0            
## [13] limma_3.42.2                GGally_1.4.0               
## [15] ggrepel_0.8.1               ComplexHeatmap_2.2.0       
## [17] scran_1.14.6                scater_1.14.6              
## [19] ggplot2_3.2.1               SingleCellExperiment_1.8.0 
## [21] SummarizedExperiment_1.16.1 DelayedArray_0.12.2        
## [23] BiocParallel_1.20.1         matrixStats_0.55.0         
## [25] Biobase_2.46.0              GenomicRanges_1.38.0       
## [27] GenomeInfoDb_1.22.0         IRanges_2.20.2             
## [29] S4Vectors_0.24.3            BiocGenerics_0.32.0        
## 
## loaded via a namespace (and not attached):
##  [1] bitops_1.0-6             httr_1.4.1               RColorBrewer_1.1-2      
##  [4] progress_1.2.2           tools_3.6.1              R6_2.4.1                
##  [7] irlba_2.3.3              vipor_0.4.5              lazyeval_0.2.2          
## [10] colorspace_1.4-1         GetoptLong_0.1.8         sp_1.3-2                
## [13] withr_2.1.2              prettyunits_1.1.1        tidyselect_1.0.0        
## [16] gridExtra_2.3            compiler_3.6.1           BiocNeighbors_1.4.1     
## [19] labeling_0.3             scales_1.1.0             stringr_1.4.0           
## [22] digest_0.6.24            rmarkdown_2.1            XVector_0.26.0          
## [25] jpeg_0.1-8.1             pkgconfig_2.0.3          htmltools_0.4.0         
## [28] rlang_0.4.4              GlobalOptions_0.1.1      DelayedMatrixStats_1.8.0
## [31] farver_2.0.3             shape_1.4.4              dplyr_0.8.4             
## [34] RCurl_1.98-1.1           BiocSingular_1.2.2       GenomeInfoDbData_1.2.2  
## [37] Matrix_1.2-18            Rcpp_1.0.3               ggbeeswarm_0.6.0        
## [40] munsell_0.5.0            viridis_0.5.1            lifecycle_0.1.0         
## [43] stringi_1.4.6            yaml_2.2.1               edgeR_3.28.0            
## [46] zlibbioc_1.32.0          plyr_1.8.5               dqrng_0.2.1             
## [49] crayon_1.3.4             lattice_0.20-40          circlize_0.4.8          
## [52] hms_0.5.3                locfit_1.5-9.1           knitr_1.28              
## [55] pillar_1.4.3             rjson_0.2.20             ggsignif_0.6.0          
## [58] reshape2_1.4.3           glue_1.3.1               evaluate_0.14           
## [61] gifski_0.8.6             tweenr_1.0.1             png_0.1-7               
## [64] vctrs_0.2.2              RgoogleMaps_1.4.5.3      tidyr_1.0.2             
## [67] gtable_0.3.0             purrr_0.3.3              clue_0.3-57             
## [70] assertthat_0.2.1         xfun_0.12                rsvd_1.0.3              
## [73] viridisLite_0.3.0        tibble_2.1.3             beeswarm_0.2.3          
## [76] cluster_2.1.0            statmod_1.4.34